<template>
  <div>
<el-button @click="closeButton()" size="small" type="primary">导入模板下载</el-button>
    <div style="margin-top:20px;"></div>
    <UploadFile
    action-url="/api/cmscloud.wholesales/orderGoods/upload"
    :initial-value="file"
    @change="successHandler"
    @error="failHandler"
    :fileTypes="['xlsx','xls']"
  >上传附件</UploadFile>
    <div style="height:47px;"></div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDrawer(1)">关 闭</el-button>
    </div>
  </div>
</template>
<script>
import moment from 'moment'
import {downloadUrl} from '@/utils'
export default {
  data(){
    return{
      urls:'/api/cmscloud.wholesales/orderGoods/upload',
      fetchParams:{

      },
      file:[],
      fetchApi:()=>{},
      isOver:true
    }
  },
  watch:{
    isOver(val){
      console.log(val,"watchIsOver")
    }
  },
  methods:{
    closeButton(type){
      this.$confirm('是否将Excel表格保存至本地文件夹?', '提示', {
          confirmButtonText: '下载',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {

          downloadUrl('https://bjev-cms-oss-public.oss-cn-beijing.aliyuncs.com/总部订单导入.xlsx','总部订单导入');

        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          });
        });
    },
    failHandler(val){
      console.log(val,"fail");
      this.isOver = true;
    },
    successHandler(val){
      if(val==1){
        this.isOver = false;
        console.log("changeIsOver");
      }else{
        this.isOver = true;
      }
      console.log(val,"success");
    },
    closeDrawer(type){
      console.log(this.file,"file");
      console.log(this.isOver,"isOver");
      if(!this.isOver){
        this.$message({
            type: 'warning',
            message: '请等待上传完成'
          });
        return;
      }
      if(type==1){
        this.$emit('close')
      }else{
        this.$emit('close',this.file)
      }

    },
  },
}

</script>
